package com.yyplatform.frontend.platform.system.repository;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import com.yyplatform.frontend.platform.system.entity.SysConfigEntity;


/**
 * Created on 2024-09-12
 */
public interface SysConfigRepository extends
        JpaRepository<SysConfigEntity, Long>, JpaSpecificationExecutor<SysConfigEntity> {
    @Query(
            value =
                    "SELECT * FROM sys_config WHERE 1=1 "
                            + " AND if(?1 != '' , `code` = ?1, 1=1 )  ",
            countQuery =
                    "SELECT count(id) FROM sys_config WHERE 1=1 "
                            + " AND if(?1 != '' , `code` = ?1, 1=1 )  ",
            nativeQuery = true)
    Page<SysConfigEntity> findPage(String code, PageRequest pageRequestOrderByIdDesc);

    SysConfigEntity findByCode(String configKey);

}
